﻿#include "mainwindow.h"
#include "ui_mainwindow.h"


intListener MainWindow::experimentStatus;//0 未启动  1 运行  2 实验结束 3 设备故障 4 打开
intListener doorStatus;//0关闭;1开启;
intListener MainWindow::tcpStatus;
intListener MainWindow::serialStatus;
intListener MainWindow::speechflagkg;
//intListener MainWindow::canRefChart;
intListener MainWindow::experimentStep;
intListener MainWindow::experimentCircle;
intListener MainWindow::startExperiment;
intListener MainWindow::tcpServerStatus;
intListener MainWindow::startExperimentStatus;
intListener passwordfl;
bool MainWindow::isRefDataAnalysis = true;

double MainWindow::tempDataOne =1;
double MainWindow::tempDataTwo =1;
double MainWindow::tempDataThree = 1;
double MainWindow::tempDataFour = 1;
double MainWindow::tempDataFive = 1;
double MainWindow::tempDataSix = 1;

int MainWindow::passWordType=0;
int MainWindow::connectType=0;
int MainWindow::tempOrder = 0;
int MainWindow::oldExperimentStatus=0;
int MainWindow::tempThreadStatus=0;
int MainWindow::stopStatus=0;

QString outpath="";
int doutfl=0;

QString MainWindow::experimentGuid = "1";
QString MainWindow::experimentSaveDataPath = "";
QString MainWindow::machineGeneticAnalysers="";
QString MainWindow::machineReagentKitType="";
QString MainWindow::machineReagentKitName="";
QString MainWindow::machineSystem="";

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    mpShadeWindow = new QWidget(this);
    MainWindow::experimentStatus.set(0);
    MainWindow::startExperiment.set(0);
    MainWindow::tcpServerStatus.set(0);
    MainWindow::speechflagkg.set(2);
    MainWindow::serialStatus.set(2);
    passwordfl.set(0);

    tcpClient=TcpClient::getInstance();
    serialPortClient=SerialportThread::getInstance();
    tcpServer=TcpServer::getInstance();

    spmoduleth = new speechModuleThread();

    ui->pushButton_7->hide();
    ui->pushButton_8->hide();



#ifdef Q_OS_ANDROID
    ui->returnBtn->setEnabled(false);
    ui->returnBtn->setText("      ");
    int fontId = QFontDatabase::addApplicationFont(":/FontStyle/AlibabaPuHuiTi-3-55-Regular.ttf");
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName, 18); // 创建一个QFont对象，设置字体名称和默认大小

            // 使用setFont方法设置字体，传入QFont对象
            ui->pushButton_3->setFont(font);
            ui->pushButton_4->setFont(font);
            ui->pushButton_5->setFont(font);
            ui->pushButton_6->setFont(font);


            // 如果需要为其他按钮设置不同的大小，可以创建新的QFont对象
            QFont smallerFont(familyName, 16);
            ui->pushButton_9->setFont(smallerFont);
            ui->pushButton_11->setFont(smallerFont);
            ui->returnBtn->setFont(smallerFont);
            ui->label->setFont(smallerFont);
            ui->label_3->setFont(smallerFont);

        }
    }

#elif defined(Q_OS_WIN)
    ui->returnBtn->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    ui->returnBtn->setEnabled(false);
    ui->returnBtn->setText("      ");
#endif
    ui->pushButton->hide();
    ui->pushButton_10->hide();
    ui->pushButton_11->hide();

    QPalette palette;
    palette.setColor(QPalette::ButtonText, QColor(255,255,255));
    ui->pushButton_2->setText("新建实验");
    ui->pushButton_2->setPalette(palette);
    MainWindow::tcpStatus.set(1);
    // 创建一个QWidget作为容器
    container = new QWidget;
    container->setWindowIcon(QIcon(":/pic/picture/96favicon.ico"));
    container->setWindowTitle("提示");
    container->setStyleSheet("background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 #007bd8,stop:0.5 #474ac1 ,stop:1 #001a5a)");
    label=new QLabel();
    label->setMinimumSize(239,303);
    label->setAlignment(Qt::AlignCenter); // 设置文本居中
    labelw=new QLabel();
    labelw->setMinimumSize(300,40);
    labelw->setMaximumSize(5000,40);
    labelw->setStyleSheet("color: rgb(255, 255, 255);");
    container->setWindowFlags(Qt::WindowStaysOnTopHint); // 设置为置顶窗口
    labelw->setAlignment(Qt::AlignCenter); // 设置文本居中
    // 创建一个垂直布局
    QVBoxLayout *layout = new QVBoxLayout(container);

    // 将QLabel和QPushButton添加到布局中
    layout->addWidget(label); // label将占据大部分空间
    layout->addWidget(labelw); // button将显示在label下方

    QObject::connect(&experimentStatus, &intListener::valueChanged, this,&MainWindow::experimentStatusChanged,Qt::QueuedConnection);
    QObject::connect(&doorStatus, &intListener::valueChanged,this,&MainWindow::doorStatusChanged,Qt::QueuedConnection);
    QObject::connect(&speechflagkg, &intListener::valueChanged,this,&MainWindow::speechflagkgChanged,Qt::QueuedConnection);
    QObject::connect(&tcpStatus, &intListener::valueChanged, this,&MainWindow::tcpStatusChanged);
    QObject::connect(&serialStatus, &intListener::valueChanged, this,&MainWindow::serialStatusChanged);
    QObject::connect(&tcpServerStatus, &intListener::valueChanged, this,&MainWindow::tcpServerChanged);
    QObject::connect(&passwordfl, &intListener::valueChanged, this,&MainWindow::passwordchange);

    this->hms.hour=0;
    this->hms.minute = 0;
    this->hms.second = 0;
    m_timer = new QTimer(this);
    m_timer->stop();    // 默认定时器关闭
    m_timer->setSingleShot(false);
    m_timer->setTimerType(Qt::PreciseTimer);

    // 间隔时间 1s
    m_timer->setInterval(1000);
    connect(m_timer, &QTimer::timeout, this, &MainWindow::do_timer_timeout);

    labelTimer = new QTimer(this);
    labelTimer->stop();    // 默认定时器关闭
    labelTimer->setSingleShot(false);
    labelTimer->setTimerType(Qt::PreciseTimer);
    labelTimer->setInterval(5000);
    connect(labelTimer, &QTimer::timeout, this, &MainWindow::closeMovieLabel);

    runTimer = new QTimer(this);
    runTimer->start();    // 默认定时器关闭
    runTimer->setSingleShot(false);
    runTimer->setTimerType(Qt::PreciseTimer);
    runTimer->setInterval(60000);
    connect(runTimer, &QTimer::timeout, this, &MainWindow::recordRunTime);

    mainMovie = new QMovie(":/pic/picture/gif1.gif");
    ui->label_5->setMovie(mainMovie);
    mainMovie->start();
    tempMovie = new QMovie();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::showEvent(QShowEvent *event)
{
    if(MainWindow::experimentStatus.get()==0){
        if(doorStatus.get()==0)
        {
            ui->pushButton_9->setText("        打开仓门");
            ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");
        }
        else
        {
            ui->pushButton_9->setText("        关闭仓门");
            ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");
        }
    }
    if(MainWindow::tcpServerStatus.get()==1){
        ui->label_6->show();
        ui->pushButton_12->show();
    }else {
        ui->label_6->hide();
        ui->pushButton_12->hide();
    }

    MainWindow::isRefDataAnalysis = true;       // 判断数据分析界面是否需要刷新 jnn
    logClient =loghelper::getInstance();

    if(MainWindow::connectType==2){
#ifdef Q_OS_ANDROID
        ui->returnBtn->setEnabled(false);
        ui->returnBtn->setText("      ");
#elif defined(Q_OS_WIN)
        ui->returnBtn->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
        ui->returnBtn->setEnabled(false);
        ui->returnBtn->setText("      ");
#endif

        ui->pushButton_3->setEnabled(false);
        ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/jy1.png);color: rgb(255, 255, 255);");

        ui->pushButton_4->setEnabled(false);
        ui->pushButton_4->setStyleSheet("border-image: url(:/pic/picture/jy2.png);color: rgb(255, 255, 255);");

        ui->pushButton_5->setEnabled(false);
        ui->pushButton_5->setStyleSheet("border-image: url(:/pic/picture/jy3.png);color: rgb(255, 255, 255);");

        ui->pushButton_9->setEnabled(false);
        ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/jy5.png);background-color: rgba(0, 0, 0, 0.3);");
        ui->pushButton_9->setText("        打开仓门");

        ui->pushButton->setEnabled(false);
        ui->pushButton_2->setEnabled(false);
        ui->pushButton_10->setEnabled(false);
        ui->pushButton_11->setEnabled(false);
    }
    else if(MainWindow::connectType!=2 && MainWindow::experimentStatus.get()==0)
    {
        ui->pushButton_3->setEnabled(true);
        ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/m1.png);color: rgb(255, 255, 255);");

        ui->pushButton_4->setEnabled(true);
        ui->pushButton_4->setStyleSheet("border-image: url(:/pic/picture/m2.png);color: rgb(255, 255, 255);");

        ui->pushButton_5->setEnabled(true);
        ui->pushButton_5->setStyleSheet("border-image: url(:/pic/picture/m3.png);color: rgb(255, 255, 255);");

        ui->pushButton->setEnabled(true);
        ui->pushButton_2->setEnabled(true);
        ui->pushButton_10->setEnabled(true);
        ui->pushButton_11->setEnabled(true);
    }

    refShadeWindow();
}

void MainWindow::resizeEvent(QResizeEvent *event){
    refShadeWindow();
}

void MainWindow::refShadeWindow(){
    if(mpShadeWindow){
        mpShadeWindow->close();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    QString sql="Select * From IsFirstStartUp";
    query.exec(sql);
    bool isFirst=false;
    int guideStatus;
    while (query.next()) {
        isFirst = query.value("IsFirst").toString()=="0";
        guideStatus = query.value("GuideStatus").toInt();
    }
    query.clear();

    if(isFirst){
        if(guideStatus==0)//网络连接
        {
            mpShadeWindow = new QWidget(this);
            QString str("QWidget{background-color:rgba(0,0,0,0.6);}");   //0.6代表透明度，根据需要自行调整
            mpShadeWindow->setStyleSheet(str);
            QRect rect = this->geometry();
            int screenWidth = rect.width();  // 屏幕宽度
            int screenHeight = rect.height();  // 屏幕高度
            mpShadeWindow->setGeometry(0, 0,screenWidth,screenHeight);    //遮罩窗口位置

            QRect btnRect= ui->pushButton_6->frameGeometry();

            QLabel *label=new QLabel("1/4网络连接",mpShadeWindow);
            QPalette palette;
            palette.setColor(QPalette::WindowText, QColor(255,255,255));
            QFont font=label->font();
            font.setPointSize(24);
            label->setFont(font);
            label->setPalette(palette);
            label->setGeometry(btnRect.x(),screenHeight-200,180,30);
            label->setStyleSheet("background-color:rgba(0,0,0,0);");

            QPushButton * btnSkipThis = new QPushButton("跳过当前引导",mpShadeWindow);
            btnSkipThis->setGeometry(btnRect.x()-60,screenHeight-150,120,40);
            btnSkipThis->setStyleSheet("border-radius: 8px; background-color:#FFFFFF");

            QObject::connect(btnSkipThis, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set GuideStatus=1";
                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton * btnSkipAll = new QPushButton("跳过全部引导",mpShadeWindow);
            btnSkipAll->setGeometry(btnRect.x()+70,screenHeight-150,120,40);
            btnSkipAll->setStyleSheet("border-radius: 8px; background-color:#2F42CD");

            QObject::connect(btnSkipAll, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set IsFirst='1',GuideStatus=5";
                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton *btnSet=new QPushButton("\n\n设置",mpShadeWindow);
            btnSet->setGeometry(btnRect.x(),screenHeight-78,85,70);
            btnSet->setStyleSheet("border-image: url(:/pic/picture/m4.png);color: rgb(255, 255, 255);");

            QLabel *movieLabel=new QLabel("",mpShadeWindow);
            movieLabel->setGeometry(btnRect.x()+60,screenHeight-78,60,60);
            movieLabel->setStyleSheet("background-color:rgba(0,0,0,0);");

            QMovie  *guideMovie = new QMovie(":/pic/picture/guide.gif");
            movieLabel->setMovie(guideMovie);
            guideMovie->start();

            QObject::connect(btnSet, &QPushButton::clicked,[this](){
                this->hide();
                emit changeSetUpWindow();
            });

            mpShadeWindow->show();
        }
        else if(guideStatus==1)//扩增程序
        {
            mpShadeWindow = new QWidget(this);
            QString str("QWidget{background-color:rgba(0,0,0,0.6);}");   //0.6代表透明度，根据需要自行调整
            mpShadeWindow->setStyleSheet(str);
            QRect rect = this->geometry();
            int screenWidth = rect.width();  // 屏幕宽度
            int screenHeight = rect.height();  // 屏幕高度
            mpShadeWindow->setGeometry(0, 0,screenWidth,screenHeight);    //遮罩窗口位置

            QRect btnRect= ui->pushButton_4->frameGeometry();

            QLabel *label=new QLabel("2/4程序",mpShadeWindow);
            QPalette palette;
            palette.setColor(QPalette::WindowText, QColor(255,255,255));
            QFont font=label->font();
            font.setPointSize(24);
            label->setFont(font);
            label->setPalette(palette);
            label->setGeometry(btnRect.x(),screenHeight-200,180,30);
            label->setStyleSheet("background-color:rgba(0,0,0,0);");

            QPushButton * btnSkipThis = new QPushButton("跳过当前引导",mpShadeWindow);
            btnSkipThis->setGeometry(btnRect.x()-60,screenHeight-150,120,40);
            btnSkipThis->setStyleSheet("border-radius: 8px; background-color:#FFFFFF");

            QObject::connect(btnSkipThis, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set GuideStatus=2";
                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton * btnSkipAll = new QPushButton("跳过全部引导",mpShadeWindow);
            btnSkipAll->setGeometry(btnRect.x()+70,screenHeight-150,120,40);
            btnSkipAll->setStyleSheet("border-radius: 8px; background-color:#2F42CD");

            QObject::connect(btnSkipAll, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                QString sql="Update IsFirstStartUp set IsFirst='1',GuideStatus=5";

                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton *btnSet=new QPushButton("\n\n程序",mpShadeWindow);
            btnSet->setGeometry(btnRect.x(),screenHeight-78,85,70);
            btnSet->setStyleSheet("border-image: url(:/pic/picture/m2.png);color: rgb(255, 255, 255);");

            QLabel *movieLabel=new QLabel("",mpShadeWindow);
            movieLabel->setGeometry(btnRect.x()+60,screenHeight-78,60,60);
            movieLabel->setStyleSheet("background-color:rgba(0,0,0,0);");

            QMovie  *guideMovie = new QMovie(":/pic/picture/guide.gif");
            movieLabel->setMovie(guideMovie);
            guideMovie->start();

            QObject::connect(btnSet, &QPushButton::clicked,[this](){
                this->hide();
                emit changeAmplWindow();
            });

            mpShadeWindow->show();
        }
        else if(guideStatus==2)//打开
        {
            mpShadeWindow = new QWidget(this);
            QString str("QWidget{background-color:rgba(0,0,0,0.6);}");   //0.6代表透明度，根据需要自行调整
            mpShadeWindow->setStyleSheet(str);
            QRect rect = this->geometry();
            int screenWidth = rect.width();  // 屏幕宽度
            int screenHeight = rect.height();  // 屏幕高度
            mpShadeWindow->setGeometry(0, 0,screenWidth,screenHeight);    //遮罩窗口位置

            QRect btnRect= ui->pushButton_3->frameGeometry();

            QLabel *label=new QLabel("3/4打开",mpShadeWindow);
            QPalette palette;
            palette.setColor(QPalette::WindowText, QColor(255,255,255));
            QFont font=label->font();
            font.setPointSize(24);
            label->setFont(font);
            label->setPalette(palette);
            label->setGeometry(btnRect.x(),screenHeight-200,180,30);
            label->setStyleSheet("background-color:rgba(0,0,0,0);");

            QPushButton * btnSkipThis = new QPushButton("跳过当前引导",mpShadeWindow);
            btnSkipThis->setGeometry(btnRect.x()-60,screenHeight-150,120,40);
            btnSkipThis->setStyleSheet("border-radius: 8px; background-color:#FFFFFF");

            QObject::connect(btnSkipThis, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                QString sql="Update IsFirstStartUp set GuideStatus=3";
                query.exec(sql);

                refShadeWindow();
            });

            QPushButton * btnSkipAll = new QPushButton("跳过全部引导",mpShadeWindow);
            btnSkipAll->setGeometry(btnRect.x()+70,screenHeight-150,120,40);
            btnSkipAll->setStyleSheet("border-radius: 8px; background-color:#2F42CD");

            QObject::connect(btnSkipAll, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set IsFirst='1',GuideStatus=5";

                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton *btnSet=new QPushButton("\n\n打开",mpShadeWindow);
            btnSet->setGeometry(btnRect.x(),screenHeight-78,85,70);
            btnSet->setStyleSheet("border-image: url(:/pic/picture/m1.png);color: rgb(255, 255, 255);");

            QLabel *movieLabel=new QLabel("",mpShadeWindow);
            movieLabel->setGeometry(btnRect.x()+60,screenHeight-78,60,60);
            movieLabel->setStyleSheet("background-color:rgba(0,0,0,0);");

            QMovie  *guideMovie = new QMovie(":/pic/picture/guide.gif");
            movieLabel->setMovie(guideMovie);
            guideMovie->start();

            QObject::connect(btnSet, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                QString sql="Update IsFirstStartUp set GuideStatus=3";
                query.exec(sql);

                on_pushButton_3_clicked();
            });

            mpShadeWindow->show();
        }
        else if(guideStatus==3)//新建实验第一步
        {
            mpShadeWindow = new QWidget(this);
            QString str("QWidget{background-color:rgba(0,0,0,0.6);}");   //0.6代表透明度，根据需要自行调整
            mpShadeWindow->setStyleSheet(str);
            QRect rect = this->geometry();
            int screenWidth = rect.width();  // 屏幕宽度
            int screenHeight = rect.height();  // 屏幕高度
            mpShadeWindow->setGeometry(0, 0,screenWidth,screenHeight);    //遮罩窗口位置

            QRect btnRect= ui->pushButton_9->frameGeometry();

            QLabel *label=new QLabel("4/4新建实验",mpShadeWindow);
            QPalette palette;
            palette.setColor(QPalette::WindowText, QColor(255,255,255));
            QFont font=label->font();
            font.setPointSize(24);
            label->setFont(font);
            label->setPalette(palette);
            label->setGeometry(btnRect.x()-130,120,180,30);
            label->setStyleSheet("background-color:rgba(0,0,0,0);");

            QPushButton * btnSkipThis = new QPushButton("跳过当前引导",mpShadeWindow);
            btnSkipThis->setGeometry(btnRect.x()-190,160,120,40);
            btnSkipThis->setStyleSheet("border-radius: 8px; background-color:#FFFFFF");

            QObject::connect(btnSkipThis, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set GuideStatus=5";
                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton * btnSkipAll = new QPushButton("跳过全部引导",mpShadeWindow);
            btnSkipAll->setGeometry(btnRect.x()-60,160,120,40);
            btnSkipAll->setStyleSheet("border-radius: 8px; background-color:#2F42CD");

            QObject::connect(btnSkipAll, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set IsFirst='1',GuideStatus=5";

                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            QPushButton *btnSet=new QPushButton("",mpShadeWindow);
            btnSet->setGeometry(btnRect.x(),0,105,56);
            btnSet->setText("        打开仓门");
            btnSet->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color:rgba(0,0,0,0.3)");

            QLabel *movieLabel=new QLabel("",mpShadeWindow);
            movieLabel->setGeometry(btnRect.x(),40,60,60);
            movieLabel->setStyleSheet("background-color:rgba(0,0,0,0);");

            QMovie  *guideMovie = new QMovie(":/pic/picture/guide.gif");
            movieLabel->setMovie(guideMovie);
            guideMovie->start();

            QObject::connect(btnSet, &QPushButton::clicked,[this](){
                on_pushButton_9_clicked();
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set GuideStatus=4";
                query.exec(sql);
                query.clear();

                refShadeWindow();
            });

            mpShadeWindow->show();
        }
        else if(guideStatus==4)//新建实验第二步
        {
            mpShadeWindow = new QWidget(this);
            ui->pushButton_2->setText("");
            QString str("QWidget{background-color:rgba(0,0,0,0.6);}");   //0.6代表透明度，根据需要自行调整
            mpShadeWindow->setStyleSheet(str);
            QRect rect = this->geometry();
            int screenWidth = rect.width();  // 屏幕宽度
            int screenHeight = rect.height();  // 屏幕高度
            mpShadeWindow->setGeometry(0, 0,screenWidth,screenHeight);    //遮罩窗口位置

            QRect btnRect= ui->pushButton_4->frameGeometry();

            QLabel *label=new QLabel("4/4新建实验",mpShadeWindow);
            QPalette palette;
            palette.setColor(QPalette::WindowText, QColor(255,255,255));
            QFont font=label->font();
            font.setPointSize(24);
            label->setFont(font);
            label->setPalette(palette);
            label->setGeometry(btnRect.x()+300,screenHeight-470,180,30);
            label->setStyleSheet("background-color:rgba(0,0,0,0);");

            QPushButton * btnSkipThis = new QPushButton("跳过当前引导",mpShadeWindow);
            btnSkipThis->setGeometry(btnRect.x()+270,screenHeight-400,120,40);
            btnSkipThis->setStyleSheet("border-radius: 8px; background-color:#FFFFFF");

            QObject::connect(btnSkipThis, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);

                QString sql="Update IsFirstStartUp set GuideStatus=5";
                query.exec(sql);
                query.clear();

                QPalette palette;
                palette.setColor(QPalette::ButtonText, QColor(255,255,255));
                ui->pushButton_2->setText("新建实验");
                ui->pushButton_2->setPalette(palette);
                refShadeWindow();
            });

            QPushButton * btnSkipAll = new QPushButton("跳过全部引导",mpShadeWindow);
            btnSkipAll->setGeometry(btnRect.x()+400,screenHeight-400,120,40);
            btnSkipAll->setStyleSheet("border-radius: 8px; background-color:#2F42CD");

            QObject::connect(btnSkipAll, &QPushButton::clicked,[this](){
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                QString sql="Update IsFirstStartUp set IsFirst='1',GuideStatus=5";
                query.exec(sql);
                query.clear();

                QPalette palette;
                palette.setColor(QPalette::ButtonText, QColor(255,255,255));
                ui->pushButton_2->setText("新建实验");
                ui->pushButton_2->setPalette(palette);
                refShadeWindow();
            });


            QPushButton *btnSet=new QPushButton("新建实验",mpShadeWindow);

#ifdef Q_OS_ANDROID
            btnSet->setGeometry(btnRect.x()-5,screenHeight-390,220,50);
#else
            btnSet->setGeometry(btnRect.x()-5,screenHeight-420,220,50);
#endif

            btnSet->setStyleSheet("background-color: rgba(0, 0, 0, 0.3); font-size:45px; color: white;font-weight: bold;");
            QLabel *movieLabel=new QLabel("",mpShadeWindow);
#ifdef Q_OS_ANDROID
            movieLabel->setGeometry(btnRect.x()+80,screenHeight-400,60,60);
#else
            movieLabel->setGeometry(btnRect.x()+80,screenHeight-430,60,60);
#endif
            movieLabel->setStyleSheet("background-color:rgba(0,0,0,0);");

            QMovie  *guideMovie = new QMovie(":/pic/picture/guide.gif");
            movieLabel->setMovie(guideMovie);
            guideMovie->start();

            QObject::connect(btnSet, &QPushButton::clicked,[this](){

                QPalette palette;
                palette.setColor(QPalette::ButtonText, QColor(255,255,255));
                ui->pushButton_2->setText("新建实验");
                ui->pushButton_2->setPalette(palette);
                this->hide();
                emit changeExpInfoWindow();
            });

            mpShadeWindow->show();
        }
    }
}

void MainWindow::experimentStatusChanged(){
    if(MainWindow::tcpServerStatus.get()==0 && MainWindow::connectType!=2)
    {
        if(MainWindow::experimentStatus.get()==0){
            ui->pushButton_2->setText("新建实验");
            ui->label_10->setText("RT-PCR-96 Analysis software V1.4");
            ui->label_4->hide();
            ui->pushButton->hide();
            ui->pushButton_10->hide();
            ui->pushButton_11->hide();

            ui->pushButton_2->setEnabled(true);

#ifdef Q_OS_ANDROID
            ui->returnBtn->setEnabled(false);
            ui->returnBtn->setText("      ");
#elif defined(Q_OS_WIN)
            ui->returnBtn->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
            ui->returnBtn->setEnabled(false);
            ui->returnBtn->setText("      ");
#endif

            ui->pushButton_3->setEnabled(true);
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/m1.png);color: rgb(255, 255, 255);");

            ui->pushButton_4->setEnabled(true);
            ui->pushButton_4->setStyleSheet("border-image: url(:/pic/picture/m2.png);color: rgb(255, 255, 255);");

            ui->pushButton_5->setEnabled(true);
            ui->pushButton_5->setStyleSheet("border-image: url(:/pic/picture/m3.png);color: rgb(255, 255, 255);");

            ui->pushButton_6->setEnabled(true);
            ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/m4.png);color: rgb(255, 255, 255);");

            ui->pushButton_9->setEnabled(true);
            ui->pushButton_9->setText("        打开仓门");
            ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");


            ui->pushButton_7->hide();
            ui->pushButton_8->hide();


            if(mainMovie){
                mainMovie->stop();
                delete mainMovie;
                mainMovie=0;
            }
            mainMovie = new QMovie(":/pic/picture/gif1.gif");
            ui->label_5->setMovie(mainMovie);
            mainMovie->start();

        }
        if(MainWindow::experimentStatus.get()==1){
            if(mainMovie){
                mainMovie->stop();
                delete mainMovie;
                mainMovie=0;
            }
            mainMovie = new QMovie(":/pic/picture/gif2.gif");
            ui->label_5->setMovie(mainMovie);
            mainMovie->start();
            ui->returnBtn->setEnabled(false);
            ui->returnBtn->setStyleSheet("border-image: url(:/pic/picture/jy6.png);"
                                         "background-color: rgba(0, 0, 0, 0.3);");
            ui->returnBtn->setText("      返回");

            ui->pushButton_7->show();
            ui->pushButton_8->show();
            ui->label_4->show();
            ui->pushButton_3->setEnabled(false);
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/jy1.png);color: rgb(255, 255, 255);");

            ui->pushButton_4->setEnabled(false);
            ui->pushButton_4->setStyleSheet("border-image: url(:/pic/picture/jy2.png);color: rgb(255, 255, 255);");

            ui->pushButton_5->setEnabled(false);
            ui->pushButton_5->setStyleSheet("border-image: url(:/pic/picture/jy3.png);color: rgb(255, 255, 255);");

            ui->pushButton_6->setEnabled(false);
            ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/jy4.png);color: rgb(255, 255, 255);");

            ui->pushButton_9->setEnabled(false);
            ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/jy5.png);background-color: rgba(0, 0, 0, 0.3);");
            ui->pushButton_9->setText("        打开仓门");

            QString duration;
            QString id="";

            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);

            QString sql=QString("Select ID,Duration From AmplProgram where id=(Select AmplGuid from ExperimentInfo where id='%1')").arg(experimentGuid);
            query.exec(sql);
            while (query.next()) {
                duration = query.value("Duration").toString();
                id=query.value("Id").toString();
            }

            sql=QString("Select CycleNum from AmplStep where ProgramId='%1' and "
                        "CASE WHEN "
                        "(Select count(*) from AmplStep where ProgramId='%1' and IsCollect='是')>0 "
                        "then "
                        "IsCollect='是' "
                        "else "
                        "StepNum=(Select max(StepNum) from AmplStep where programId='%1') "
                        "end").arg(id);
            query.exec(sql);
            while (query.next()) {
                CycleNum = query.value("CycleNum").toString();
            }

            ui->pushButton->show();
            ui->pushButton_10->show();
            ui->pushButton_11->show();

            sql="Select ExperimentName from ExperimentInfo";
            query.exec(sql);
            while (query.next()) {
                QString fileName=query.value("ExperimentName").toString();
                ui->label_10->setText(fileName);
            }

            QPalette palette;
            palette.setColor(QPalette::ButtonText, QColor(255,255,255));

            ui->pushButton_2->setPalette(palette);
            ui->pushButton_2->setText("00:00");
            ui->pushButton_2->setEnabled(false);

            ui->pushButton_11->setPalette(palette);
            ui->pushButton_11->setText(QString ("0/%1").arg(CycleNum));

            palette.setColor(QPalette::ButtonText, QColor(144,251,255));
            ui->pushButton->setPalette(palette);
            ui->pushButton->setText("正在运行");


            palette.setColor(QPalette::ButtonText, QColor(156,186,255));
            ui->pushButton_10->setPalette(palette);
            ui->pushButton_10->setText("0°C");

            double hour=0;
            double min=0;
            double second=0;

            if(duration.contains("时")){
                QStringList hourList=  duration.split("时");
                hour=hourList[0].toDouble();
                duration.remove(0,hourList[0].length());
                duration.remove("时");
            }
            if(duration.contains("分")){
                QStringList hourList=  duration.split("分");
                min=hourList[0].toDouble();
                duration.remove(0,hourList[0].length());
                duration.remove("分");
            }
            if(duration.contains("秒")){
                QStringList hourList=  duration.split("秒");
                second=hourList[0].toDouble();
            }

            this->hms.hour = hour;
            this->hms.minute = min;
            this->hms.second = second;
            m_timer->start();
        }
        if(MainWindow::experimentStatus.get()==2){


            DebugLog::debug(DEBUG_CONTEXT, "MainWindow::experimentStatus.get()==2 start");
            if(mainMovie){
                mainMovie->stop();
                delete mainMovie;
                mainMovie=0;
            }
            mainMovie = new QMovie(":/pic/picture/gif3.gif");
            ui->label_5->setMovie(mainMovie);
            mainMovie->start();

            ui->pushButton_7->hide();
            ui->pushButton_8->hide();
            ui->label_4->hide();

            ui->pushButton->show();
            ui->pushButton_10->hide();
            ui->pushButton_11->hide();

            ui->returnBtn->setText("      返回");
            ui->returnBtn->setEnabled(true);
            ui->returnBtn->setStyleSheet("border-image: url(:/pic/picture/t9.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");

            ui->pushButton->setText("已完成");
            ui->pushButton_2->setText("导出报告");
            ui->pushButton_2->setEnabled(true);

            QPalette palette;
            palette.setColor(QPalette::ButtonText, QColor(255,255,255)); // 将字体颜色设置为红色
            ui->pushButton_2->setPalette(palette);
            ui->pushButton_11->setPalette(palette);

            palette.setColor(QPalette::ButtonText, QColor(255,188,13)); // 将字体颜色设置为红色
            ui->pushButton->setPalette(palette);

            palette.setColor(QPalette::ButtonText, QColor(156,186,255)); // 将字体颜色设置为红色
            ui->pushButton_10->setPalette(palette);

            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);

            QString sql="Update StaticNumInfo Set ExpNum=ExpNum+1 ";
            query.exec(sql);

            sql="Update StaticNumInfo Set TestSampleNum=TestSampleNum+(Select count(Distinct s.Id) as Sums from sampleInfo s "
                "Join SampleAccessInfo a on s.Id=a.SampleGuid )";
            query.exec(sql);

            sql="Select RunTime From ExperimentInfo";
            query.exec(sql);
            QString runTime;
            while (query.next())
            {
                runTime=query.value("RunTime").toString();
            }
            QString finishTime= common->GetDateTimeStr();

            QDateTime start = QDateTime::fromString(runTime, "yyyy-MM-ddTHH:mm:ss");
            QDateTime end = QDateTime::fromString(finishTime, "yyyy-MM-ddTHH:mm:ss");
            int seconds = start.secsTo(end);

            sql=QString("Update StaticNumInfo Set TestTime=(TestTime*3600+%1)/3600.0").arg(QString::number(seconds));
            query.exec(sql);

            QString endTime = common->GetDateTimeStr();
            sql= QString("Update ExperimentInfo set Status='完成',FinishTime='%2' where id='%1'").arg(MainWindow::experimentGuid,endTime);
            query.exec(sql);

            if(MainWindow::stopStatus==0){
                ExportWlk::run();
                DataAnalysis* da = new DataAnalysis();        // 自动导出
                da->datao();
                if(da){
                    delete da;
                    da = nullptr;
                }
            }
            DebugLog::debug(DEBUG_CONTEXT, "MainWindow::experimentStatus.get()==2 end");
        }
        if(MainWindow::experimentStatus.get()==3){
            if(mainMovie){
                mainMovie->stop();
                delete mainMovie;
                mainMovie=0;
            }
            mainMovie = new QMovie(":/pic/picture/gif4.gif");
            ui->label_5->setMovie(mainMovie);
            mainMovie->start();
            ui->label_4->hide();

            ui->pushButton->show();
            ui->pushButton_10->hide();
            ui->pushButton_11->hide();
            ui->pushButton->setText("故障");
            ui->pushButton_2->setText("设备异常");
            ui->pushButton_2->setEnabled(true);
            ui->returnBtn->setEnabled(true);
            ui->returnBtn->setStyleSheet("border-image: url(:/pic/picture/t9.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");

            QPalette palette;
            palette.setColor(QPalette::ButtonText, QColor(255,255,255)); // 将字体颜色设置为红色
            ui->pushButton_2->setPalette(palette);

            palette.setColor(QPalette::ButtonText, QColor(255,13,13)); // 将字体颜色设置为红色
            ui->pushButton->setPalette(palette);

            ui->pushButton_3->setEnabled(true);
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/m1.png);color: rgb(255, 255, 255);");

            ui->pushButton_4->setEnabled(true);
            ui->pushButton_4->setStyleSheet("border-image: url(:/pic/picture/m2.png);color: rgb(255, 255, 255);");

            ui->pushButton_5->setEnabled(true);
            ui->pushButton_5->setStyleSheet("border-image: url(:/pic/picture/m3.png);color: rgb(255, 255, 255);");

            ui->pushButton_6->setEnabled(true);
            ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/m4.png);color: rgb(255, 255, 255);");

            ui->pushButton_7->hide();
            ui->pushButton_8->hide();
        }
    }

    if(MainWindow::tcpServerStatus.get()==1 && MainWindow::experimentStatus.get()==2){

        DebugLog::debug(DEBUG_CONTEXT, "MainWindow::experimentStatus.get()==2 start");


        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);

        QString sql="Update StaticNumInfo Set ExpNum=ExpNum+1 ";
        query.exec(sql);

        sql="Update StaticNumInfo Set TestSampleNum=TestSampleNum+(Select count(Distinct s.Id) as Sums from sampleInfo s "
            "Join SampleAccessInfo a on s.Id=a.SampleGuid )";
        query.exec(sql);

        sql="Select RunTime From ExperimentInfo";
        query.exec(sql);
        QString runTime;
        while (query.next())
        {
            runTime=query.value("RunTime").toString();
        }
        QString finishTime= common->GetDateTimeStr();

        QDateTime start = QDateTime::fromString(runTime, "yyyy-MM-ddTHH:mm:ss");
        QDateTime end = QDateTime::fromString(finishTime, "yyyy-MM-ddTHH:mm:ss");
        int seconds = start.secsTo(end);

        sql=QString("Update StaticNumInfo Set TestTime=(TestTime*3600+%1)/3600.0").arg(QString::number(seconds));
        query.exec(sql);

        QString endTime = common->GetDateTimeStr();
        sql= QString("Update ExperimentInfo set Status='完成',FinishTime='%2' where id='%1'").arg(MainWindow::experimentGuid,endTime);
        query.exec(sql);
        if(MainWindow::stopStatus==0)
        {
            ExportWlk::run();
            DataAnalysis* da = new DataAnalysis();        // 自动导出
            da->datao();
            if(da){
                delete da;
                da = nullptr;
            }
        }
        MainWindow::experimentStatus.set(0);

        DebugLog::debug(DEBUG_CONTEXT, "MainWindow::experimentStatus.get()==2 end");

    }
}

void MainWindow::doorStatusChanged(){
    if(MainWindow::experimentStatus.get()!=1){
        if(MainWindow::tcpStatus.get()==0){
            if(doorStatus.get()==0)//舱门打开状态,关闭舱门
            {
                QString finalData="62 00 00 3D 00 0A 00 03 00 02 00 00 00 00 55 AA";
                QByteArray finalInfo=common->GetSendData(finalData);
                if(MainWindow::connectType==0){
                    tcpClient->ClientSendingData(finalInfo);
                }
                else if(MainWindow::connectType==1){
                    serialPortClient->ClientSendingData(finalInfo);
                }
                ui->pushButton_9->setText("        打开仓门");
                ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");

                if(MainWindow::tcpServerStatus.get()==1){
                    QString data="62 00 00 3A 00 06 03 01";
                    QString checkedData= common->GetCrcCheck(data.toLatin1());

                    QString serverData=QString("62 00 00 3A 00 06 03 01 %1 AA 55").arg(checkedData);
                    logClient->WriteLog("ServerLog","发送:\n"+serverData);

                    QByteArray finalServerInfo=common->GetSendData(serverData);
                    tcpServer->sendData(finalServerInfo);
                    tcpServer->closeConnect();
                }
                else {
                    QMovie *movieDoor = new QMovie(":/pic/picture/closeDoor.gif");
                    // 获取屏幕的中心点
                    QRect screenGeometry = QApplication::desktop()->screenGeometry();
                    int centerX = screenGeometry.center().x();
                    int centerY = screenGeometry.center().y();

                    // 计算QLabel的位置，使其中心与屏幕中心对齐
                    int labelWidth = container->sizeHint().width(); // 获取QLabel的建议大小
                    int labelHeight = container->sizeHint().height();
                    int labelX = centerX - (labelWidth / 2);
                    int labelY = centerY - (labelHeight / 2);

                    // 设置QLabel的位置
                    container->move(labelX, labelY);
                    label->setMovie(movieDoor);
                    movieDoor->start();
                    labelw->setText("仓门正在关闭，请勿进行其它操作");

                    container->close();
                    container->show();
                    labelTimer->start();
                }
            }
            else //舱门关闭状态,打开舱门
            {
                QString finalData="62 00 00 3D 00 0A 00 03 00 01 00 00 00 00 55 AA";
                QByteArray finalInfo=common->GetSendData(finalData);
                if(MainWindow::connectType==0){
                    tcpClient->ClientSendingData(finalInfo);
                }
                else if(MainWindow::connectType==1){
                    serialPortClient->ClientSendingData(finalInfo);
                }
                ui->pushButton_9->setText("        关闭仓门");
                ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");

                if(MainWindow::tcpServerStatus.get()==1){
                    QString data="62 00 00 3A 00 06 02 01";
                    QString checkedData= common->GetCrcCheck(data.toLatin1());

                    QString serverData=QString("62 00 00 3A 00 06 02 01 %1 AA 55").arg(checkedData);
                    logClient->WriteLog("ServerLog","发送:\n"+serverData);

                    QByteArray finalServerInfo=common->GetSendData(serverData);
                    tcpServer->sendData(finalServerInfo);
                    tcpServer->closeConnect();
                }else {
                    QMovie *movieDoor = new QMovie(":/pic/picture/openDoor.gif");

                    // 获取屏幕的中心点
                    QRect screenGeometry = QApplication::desktop()->screenGeometry();
                    int centerX = screenGeometry.center().x();
                    int centerY = screenGeometry.center().y();

                    // 计算QLabel的位置，使其中心与屏幕中心对齐
                    int labelWidth = container->sizeHint().width(); // 获取QLabel的建议大小
                    int labelHeight = container->sizeHint().height();
                    int labelX = centerX - (labelWidth / 2);
                    int labelY = centerY - (labelHeight / 2);

                    // 设置QLabel的位置
                    container->move(labelX, labelY);
                    label->setMovie(movieDoor);

                    movieDoor->start();
                    container->close();
                    container->show();
                    labelw->setText("仓门正在打开，请勿进行其它操作");
                    labelTimer->start();
                }
            }
        }
        else
        {
            QMessageBox *box = new QMessageBox(QMessageBox::Question, "提示", "未连接设备,请先连接设备", QMessageBox::Yes | QMessageBox::No, this);
            box->button(QMessageBox::Yes)->setText("确认");// 将原本显示“Yes”的按钮改为显示“确认”
            box->button(QMessageBox::No)->setText("取消");// 将原本显示“No”的按钮改为显示“取消”
            int res = box->exec();// 启动对话框，用res变量记录用户最终点选的按钮
        }
    }
}

void MainWindow::tcpStatusChanged(){
    if(MainWindow::tcpStatus.get()==1){
        if(MainWindow::experimentStatus.get()==1){
            MainWindow::experimentStatus.set(3);
        }
        ui->label_2->setStyleSheet("border-image: url(:/pic/picture/tx1.png);");
        ui->label_3->setText("未连接");
    }else {
        if(MainWindow::experimentStatus.get()==1){
            MainWindow::experimentStatus.set(0);
        }
        ui->label_2->setStyleSheet("border-image: url(:/pic/picture/tx2.png);");
        ui->label_3->setText("已连接");
    }
}

void MainWindow::serialStatusChanged(){
    if(MainWindow::serialStatus.get()==1){
        if(MainWindow::experimentStatus.get()==1){
            //            MainWindow::experimentStatus.set(3);
        }
        ui->label_2->setStyleSheet("border-image: url(:/pic/picture/ck1.png);");
        ui->label_3->setText("已连接");
    }
    else if(MainWindow::serialStatus.get()==0){
        if(MainWindow::experimentStatus.get()==1){
            MainWindow::experimentStatus.set(0);
        }
        ui->label_2->setStyleSheet("border-image: url(:/pic/picture/ck0.png);");
        ui->label_3->setText("未连接");
    }
}

void MainWindow::tcpServerChanged(){
    if(MainWindow::tcpServerStatus.get()==1){
        if(mainMovie){
            mainMovie->stop();
            delete mainMovie;
            mainMovie=0;
        }

        ui->pushButton->hide();
        ui->pushButton_10->hide();
        ui->pushButton_11->hide();
        ui->label_5->setStyleSheet("border-image: url(:/pic/picture/t5.png);");
        ui->pushButton_2->setText("联机中");
        ui->pushButton_3->hide();
        ui->pushButton_4->hide();
        ui->pushButton_5->hide();
        ui->pushButton_6->hide();
        ui->pushButton_12->show();
        ui->pushButton_7->hide();
        ui->pushButton_8->hide();
        ui->label_6->show();
        ui->label->hide();
        ui->label_2->hide();
        ui->label_3->hide();
        ui->pushButton_2->setEnabled(false);
        ui->pushButton_9->setEnabled(false);
        ui->pushButton_9->setStyleSheet("border-image: url(:/pic/picture/t10.png);color: rgb(255, 255, 255);background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        ui->label->show();
        ui->label_2->show();
        ui->label_3->show();
        ui->pushButton_3->show();
        ui->pushButton_4->show();
        ui->pushButton_5->show();
        ui->pushButton_6->show();
        ui->pushButton_12->hide();
        ui->label_6->hide();

        experimentStatusChanged();
    }
}

void MainWindow::speechflagkgChanged(){
    spmoduleth->run();
}

void MainWindow::on_pushButton_6_clicked()
{
    this->hide();
    emit changeSetUpWindow();
}

void MainWindow::on_pushButton_4_clicked()
{
    this->hide();
    emit changeAmplWindow();
}

void MainWindow::on_pushButton_3_clicked()
{

    // DataAnalysis da; da.datao();

    this->hide();

#ifdef Q_OS_ANDROID
    JNIManager::I().getUSBPath();
#endif
    emit changeopenfileWindow();
}

void MainWindow::do_timer_timeout()
{
    if(MainWindow::experimentStatus.get()!=1){
        m_timer->stop();
        return;
    }
    bool retBool = this->subtractOneSecond();

    if(retBool){
        QString hour=QString::number(hms.hour).length()< 2?"0"+QString::number(hms.hour):QString::number(hms.hour);
        QString minute=QString::number(hms.minute).length()<2?"0"+QString::number(hms.minute):QString::number(hms.minute);
        QString second=QString::number(hms.second).length()<2?"0"+QString::number(hms.second):QString::number(hms.second);

        ui->pushButton_2->setText(hour+":"+ minute+":"+second);
    }
    QString temp=QString::number(MainWindow::tempDataOne,'f',2);
    double newTemp=temp.toDouble();

    QString oldTempString=ui->pushButton_10->text();
    QList<QString> oldTempList=oldTempString.split("°");
    double oldTemp=oldTempList[0].toDouble();

    if(newTemp>oldTemp){
        if(tempMovie){
            tempMovie->stop();
            delete tempMovie;
            tempMovie=0;
        }
        tempMovie= new QMovie(":/pic/picture/sw.gif");
        ui->label_4->setMovie(tempMovie);
        tempMovie->start();
    }
    else if(newTemp<oldTemp)
    {
        if(tempMovie){
            tempMovie->stop();
            delete tempMovie;
            tempMovie=0;
        }
        tempMovie = new QMovie(":/pic/picture/jw.gif");
        ui->label_4->setMovie(tempMovie);
        tempMovie->start();
    }

    ui->pushButton_10->setText(QString::number(temp.toDouble(),'f',2)+"°C");
    ui->pushButton_11->setText(QString("%1/%2").arg(QString::number(MainWindow::experimentCircle.get()),CycleNum));
}

// 减一秒
bool MainWindow::subtractOneSecond()
{
    // 若全部等于0，则返回false
    if(hms.second <= 0 && hms.minute == 0&& hms.hour==0){
        return false;
    }
    // 秒钟减1
    hms.second--;
    if(hms.second < 0){
        hms.minute--;
        hms.second = 59;
        if(hms.minute<0 && hms.hour>0){
            hms.hour--;
            hms.minute=59;
        }
    }
    return true;
}

void MainWindow::on_pushButton_8_clicked()
{
    this->hide();
    emit changeSampleWindow();
}

void MainWindow::on_pushButton_7_clicked()
{
    this->hide();
    emit changeExpeWindow();
}

void MainWindow::on_returnBtn_clicked()
{
    MainWindow::experimentStatus.set(0);
}

void MainWindow::on_pushButton_9_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
    }
    else
    {
        doorStatus.set(0);
    }
}


void MainWindow::closeMovieLabel(){
    container->close();
    labelTimer->stop();
}

void MainWindow::on_pushButton_5_clicked()
{
    MainWindow::passWordType=0;

    emit changeMaintainWindow();
}

void MainWindow::on_pushButton_clicked()
{
    if(MainWindow::experimentStatus.get()==2){
        this->hide();
        emit changeAnalyWindow();
    }
}

void MainWindow::on_pushButton_2_clicked()
{
    if(MainWindow::experimentStatus.get()==0){
        if(MainWindow::tcpStatus.get()==1&& (MainWindow::serialStatus.get() == 0 || MainWindow::serialStatus.get() ==2))
        {
            // 创建一个question弹出对话框，添加两个按钮：Yes和No
            QMessageBox *box = new QMessageBox(QMessageBox::Question, "提示", "未连接设备,请先连接设备", QMessageBox::Yes | QMessageBox::No, this);
            box->button(QMessageBox::Yes)->setText("确认");// 将原本显示“Yes”的按钮改为显示“确认”
            box->button(QMessageBox::No)->setText("取消");// 将原本显示“No”的按钮改为显示“取消”
            int res = box->exec();// 启动对话框，用res变量记录用户最终点选的按钮
            if(QMessageBox::Yes == res)
            {
                this->hide();
                emit changeSetUpWindow();
            }
        }else{
            this->hide();
            emit changeExpInfoWindow();
        }
    }
    else if(MainWindow::experimentStatus.get()==4){
        if(MainWindow::tcpStatus.get()==1){
            // 创建一个question弹出对话框，添加两个按钮：Yes和No
            QMessageBox *box = new QMessageBox(QMessageBox::Question, "提示", "未连接设备,请先连接设备", QMessageBox::Yes | QMessageBox::No, this);
            box->button(QMessageBox::Yes)->setText("确认");// 将原本显示“Yes”的按钮改为显示“确认”
            box->button(QMessageBox::No)->setText("取消");// 将原本显示“No”的按钮改为显示“取消”
            int res = box->exec();// 启动对话框，用res变量记录用户最终点选的按钮
            if(QMessageBox::Yes == res)
            {
                this->hide();
                emit changeSetUpWindow();
            }
        }else{
            MainWindow::experimentStatus.set(0);
            this->hide();
            emit changeExpInfoWindow();
        }
    }
    else if(MainWindow::experimentStatus.get()==3){
        this->hide();
        emit changeErrorWindow();
    }else if(MainWindow::experimentStatus.get()==2){

        DebugLog::write("实验完成 - 手动导出报告");

        doutfl=1;
        // 获取用户选择的文件夹路径
#ifdef Q_OS_ANDROID
        DialogFileManager dfm(1);
        dfm.exec();
        if(dfm.getResult() == ""){
            return;
        }
        outpath = dfm.getResult();
        DataAnalysis da;
        da.datao(outpath);
        doutfl=0;
#else

        QString saveName = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
        QString filePath = QFileDialog::getSaveFileName(nullptr, "保存", "/path/to/default/"+saveName, "Xlsx files(*.xlsx)");
        if(filePath.isEmpty()|| filePath.isNull()){
            return;
        }
        DataAnalysis da;
        da.datao(filePath, 1);
        doutfl=0;

#endif

    }
}

void MainWindow::on_pushButton_10_clicked()
{
    if(MainWindow::experimentStatus.get()==1){
        this->hide();
        emit changeExpTempWindow();
    }
}

void MainWindow::on_pushButton_12_clicked()
{
    tcpServer->closeConnect();
    MainWindow::tcpServerStatus.set(0);
}

void MainWindow::passwordchange()
{
    if(MainWindow::passWordType==0 && passwordfl.get()==1){
        this->hide();
        passwordfl.set(0);
    }
}

void MainWindow::recordRunTime(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    QString sql="Update StaticNumInfo Set RunningTime=(RunningTime*3600.0+60)/3600.0";
    query.exec(sql);
}
